package service

import (
	"context"
	"gorm.io/gorm"
	"shop-common/library/variables"
	"shop-service/repository"
)

type IProdTagReferenceService interface {
	ListTagIdByProdId(ctx context.Context, prodId uint) ([]uint, error)
}

type ProdTagReferenceService struct {
	db         *gorm.DB
	repository repository.IProdTagReferenceRepository
}

func NewProdTagReferenceService(repository repository.IProdTagReferenceRepository) IProdTagReferenceService {
	return &ProdTagReferenceService{variables.GormDB(), repository}
}

func (s *ProdTagReferenceService) ListTagIdByProdId(ctx context.Context, prodId uint) ([]uint, error) {
	list, err := s.repository.FindTagIdByProdId(s.db, prodId)
	if err != nil {
		variables.Logger.Errorf(ctx, "findTagIdByProdId to tags failed: err %v, prodId %d", err, prodId)
		return nil, err
	}

	return list, nil
}
